import { defineConfig } from "vite";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
import vue from "@vitejs/plugin-vue";
import { viteMockServe } from "vite-plugin-mock";
// https://vitejs.dev/config/

export default defineConfig({
  css: {
    preprocessorOptions: {
      scss: {
        api: "modern-compiler" // or 'modern'
      }
    }
  },
  devServer: {
    /*1.测试成功 配合配置文件使用 VUE_APP_URL = 'https://localhost:44367/api'*/
    proxy: {
      "/aliyun": {
        // api 表示拦截以 /api开头的请求路径
        target: "https://devops.aliyun.com", //跨域的域名（不需要写路径）
        changeOrigin: true, //是否开启跨域
      },
    },
  },
  resolve: {
    //别名
    alias: {
      "@": "/src",
    },
  },
  plugins: [
    vue({
      include: [/\.vue$/],
    }),
    viteMockServe({
      supportTs: false, //是否开启支持ts
      mockPath: "mock", //设置mockPath为根目录下的mock目录,为根目录
      localEnabled: true, // 开发打包开关 true时打开mock  false关闭mock
      prodEnabled: false, //prod环境下是否可以使用mock
      logger: true, //是否在控制台显示请求日志
    }),
    AutoImport({
      imports: ["vue", "vue-router", { "ant-design-vue": ["message", "Modal"] }],
      dts: "./auto-import.d.ts",
      dirs: ["src/composables"],
    }),
    Components({
      resolvers: [
        AntDesignVueResolver({
          importStyle: false, // css in js
        }),
      ],
      dirs: ["src/components"],
      dts: true,
      directoryAsNamespace: true,
    }),
  ],
});
